async function async1(){
  console.log('async1 start');
   await async2();
  // await async3()
   console.log('async1 end')
}
async function async2(){
  console.log('async2222')
  setTimeout(()=>{
    console.log('async2')
  },2000)
  
}

async function async3(){
  console.log('async333')
  setTimeout(()=>{
    console.log('async 3')
  },1000)
}
// console.log('script start');
// async1();
// async3()
// console.log('script end')
// 输出顺序：script start->async1 start->async2->script end->async1 end


function timeout(ms) {
  return new Promise((resolve) => {
    setTimeout(resolve, ms);
  });
}

async function asyncPrint(value, ms) {
  await timeout(ms);
  console.log(value);
}

asyncPrint('hello world', 2000);


async function f() {
  throw new Error('出错了');
}

f().then(
  v => console.log('resolve', v),
  e => console.log('reject', e)
)